//*****************************************************************************
// JFab (http://code.google.com/p/jfab)
// Copyright (c) 2011-2012 JFab.org
// Admin jfab@jeffreythompson.net
//
// See the file "LICENSE.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//*****************************************************************************

package org.jfab.swingui.decorator;

import javax.swing.Icon;

import org.jfab.core.model.CGConcreteUnit;
import org.jfab.core.model.CGInitializationBlock;
import org.jfab.swingui.IconManager;
import org.jfab.swingui.editpane.CGInitializationBlockEditPane;
import org.jfab.swingui.editpane.EditPane;

/**
 * Provides a decorator implementation for <code>CGInitializationBlock</code>.
 */
public class CGInitializationBlockDecorator extends
        CGObjectDecorator<CGInitializationBlock>
{
    /**
     * Construct this object with the given parameter.
     * 
     * @param component Component.
     * @param parent Parent.
     * @param iconManager Icon manager.
     */
    public CGInitializationBlockDecorator(
            final CGInitializationBlock component, final Decorator<?> parent,
            final IconManager iconManager)
    {
        super(component, parent, iconManager);
    }

    @Override
    public void addNode(final String childTypeName)
    {
        // Nothing to do.
    }

    @Override
    public Object getChild(final int index)
    {
        return null;
    }

    @Override
    public int getChildCount()
    {
        return 0;
    }

    @Override
    public String[] getChildSelectionValues()
    {
        return null;
    }

    /**
     * @see org.jfab.swingui.decorator.Decorator#getDisplayName()
     */
    @Override
    public String getDisplayName()
    {
        return "initialization block";
    }

    @Override
    public EditPane<CGInitializationBlock> getEditPane()
    {
        return new CGInitializationBlockEditPane(getComponent());
    }

    @Override
    public Icon getIcon()
    {
        return getIconManager().getInitializationBlockIcon();
    }

    @Override
    public int getIndexOfChild(final Object child)
    {
        return -1;
    }

    @Override
    public boolean isLeaf()
    {
        return true;
    }

    @Override
    public boolean removeNode()
    {
        final CGConcreteUnitDecorator<?> parent = (CGConcreteUnitDecorator<?>)getParent();
        final CGConcreteUnit cgCompilationUnit = parent.getComponent();

        return cgCompilationUnit.getInitializationBlocks().remove(
                getComponent());
    }
}
